//
//  ThemeScrollViewIndicatorStylePicker.swift
//  HeadlineNews
//
//  Created by han on 2019/7/26.
//  Copyright © 2019 han. All rights reserved.
//

import UIKit

final class ThemeScrollViewIndicatorStylePicker: ThemePicker {
    convenience init(keyPath: String) {
        self.init(v: { ThemeScrollViewIndicatorStylePicker.getStyle(stringStyle: ThemeManager.string(for: keyPath) ?? "") })
    }
    
    convenience init(keyPath: String, map: @escaping (Any?) -> UIScrollView.IndicatorStyle) {
        self.init(v: { map(ThemeManager.value(for: keyPath))})
    }
    
    convenience init(styles: UIScrollView.IndicatorStyle...) {
        self.init(v: { ThemeManager.element(for: styles) })
    }
}

extension ThemeScrollViewIndicatorStylePicker {
   class func getStyle(stringStyle: String) -> UIScrollView.IndicatorStyle{
        switch stringStyle.lowercased()   {
        case "default": return .default
        case "black": return .black
        case "white": return .white
        default: return .default
        }
    }
}

extension ThemeScrollViewIndicatorStylePicker: ExpressibleByArrayLiteral {
    convenience init(arrayLiteral elements: UIScrollView.IndicatorStyle...) {
        self.init(v: { ThemeManager.element(for: elements) })
    }
}

extension ThemeScrollViewIndicatorStylePicker: ExpressibleByStringLiteral {
    convenience init(stringLiteral value: String) {
        self.init(keyPath: value)
    }
    convenience init(extendedGraphemeClusterLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeScrollViewIndicatorStylePicker: ExpressibleByUnicodeScalarLiteral {
    convenience init(unicodeScalarLiteral value: String) {
        self.init(keyPath: value)
    }
}

extension ThemeScrollViewIndicatorStylePicker {
    class func pickerWithKeyPath(_ keyPath: String) -> ThemeScrollViewIndicatorStylePicker{
        return ThemeScrollViewIndicatorStylePicker(keyPath: keyPath)
    }
    
    class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> UIScrollView.IndicatorStyle) -> ThemeScrollViewIndicatorStylePicker {
        return ThemeScrollViewIndicatorStylePicker(v: { map(ThemeManager.value(for: keyPath)) })
    }
    
    class func pickerWithStyles(_ styles: [UIScrollView.IndicatorStyle]) -> ThemeScrollViewIndicatorStylePicker {
        return ThemeScrollViewIndicatorStylePicker(v: { ThemeManager.element(for: styles) })
    }
    
    class func pickerWithStyles(_ styles: [String]) -> ThemeScrollViewIndicatorStylePicker {
        return ThemeScrollViewIndicatorStylePicker(v: { ThemeManager.element(for: styles.map(getStyle))})
    }
}
